package version;

//商圈管理员管理

import o2o.config.dao.UserDaoSql;
import o2o.config.dao.utils.DaoUtils;
import o2o.config.dao.utils.Expression;
import o2o.config.dao.utils.QueryCondition;
import com.jinyou.utils.common.ValidateUtil;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SysAppVersionMemory {
    public static final String TABLENAME = "app_version";


    // 创建单例模式
    private SysAppVersionMemory() {
    }

    static class InstanceHolder {
        private static SysAppVersionMemory single = new SysAppVersionMemory();
    }

    public static SysAppVersionMemory getInstance() {
        return InstanceHolder.single;
    }


    //获取应用版本
    public SysAppVersion getAppVersion(Integer typeId) {
        QueryCondition query = QueryCondition.getInstance();
        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("typeId",typeId));//所有未删除的
        String sql = DaoUtils.getSql(TABLENAME, query);
        sql+=" order by currVersionCode desc";
        SysAppVersion res = null;
        try {
            res = (SysAppVersion) UserDaoSql.getInstance().getObject(SysAppVersion.class, sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return res;
    }

    //获取所有应用版本
    public List<SysAppVersion> getAppVersionList() {
        QueryCondition query = QueryCondition.getInstance();
        query.addCondition(Expression.getInstance().addChild("delFlag", 0));//所有未删除的
        String sql = DaoUtils.getSql(TABLENAME, query);
        List<SysAppVersion> list = null;
        try {
            list = (List<SysAppVersion>) UserDaoSql.getInstance().list(SysAppVersion.class, sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
